<template>
  <el-container>
    <el-aside width="200px">
      <el-menu
        :default-active="$route.path"
        class="menu"
        mode="vertical"
        router
      >
        <el-submenu
          :index="`${index} + 1`"
          :key="`menu-item-${index}`"
          v-for="(submenu, index) in menu.submenus"
        >
          <template slot="title">{{ submenu.title }}</template>
          <el-menu-item
            :index="item.path"
            :key="`item-${i}`"
            v-for="(item, i) in submenu.items"
          >
            {{ item.title }}
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header>
        <h3>后台管理界面</h3>
      </el-header>
      <el-main>
        <router-view :key="$route.path"></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'

@Component({})
export default class Main extends Vue {
  menu = {
    submenus: [
      // 菜单中的选项
      {
        title: '内容管理',
        items: [
          // 子级菜单的选项
          {
            title: '首页',
            path: '/',
          },
          {
            title: '课程管理',
            path: '/courses/list',
          },
          {
            title: '课时管理',
            path: '/episodes/list',
          },
        ],
      },
      {
        title: '运营管理',
        items: [
          // 子级菜单的选项
          {
            title: '用户管理',
            path: '/users/list',
          },
        ],
      },
    ],
  }
}
</script>

<style>
body {
  padding: 0;
  margin: 0;
}

.menu {
  min-height: 100vh;
  height: 100%;
}
</style>
